package io.renren.modules.alarm.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.alarm.dao.AlarmListDao;
import io.renren.modules.alarm.entity.AlarmListEntity;
import io.renren.modules.alarm.entity.AlarmValueEntity;
import io.renren.modules.alarm.service.AlarmListService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AlarmListServiceImpl implements AlarmListService {

    @Resource
    private AlarmListDao alarmListMapper;

    @Override
    public PageUtils getList(Map<String, Object> params) {
        IPage<AlarmListEntity> page = alarmListMapper.getList(new Query<AlarmListEntity>().getPage(params), params);
        return new PageUtils(page);
    }

    @Override
    public R get(Integer id) {
        return R.ok(alarmListMapper.get(id));
    }

    //综合看板
    @Override
    public R integratedSignage(String spaceName) {
        return R.ok(alarmListMapper.integratedSignage(spaceName));
    }

    //综合看板，健康值和舒适度
    @Override
    public R getHealthOrComfort(String spaceName){
        AlarmListUtil alarm = new AlarmListUtil();
        String health = alarm.getHealthOrComfort("health", spaceName);
        String comfort = alarm.getHealthOrComfort("comfort", spaceName);
        Map<String, String> map = new HashMap<>();
        map.put("health",health);
        map.put("comfort",comfort);
        return R.ok(map);
    }

    //获取报警数据集合
    @Override
    public R getAlarmValueList(String id) {
        String alarmValueList = alarmListMapper.getAlarmValueList(id);
        List<AlarmValueEntity> list = JSON.parseArray(alarmValueList,AlarmValueEntity.class);
        return R.ok(list);
    }
}
